package com.fengxing.ams.web.facade.mouble.realtime;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;

import com.fengxing.ams.pub.util.StringUtil;

@Entity
@Table(name = "zyt_realtime_student")
public class RealtimeStudentVO {
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer id;

	@ManyToOne(cascade = { CascadeType.ALL}, optional = false)
    @JoinColumn(name = "school_id") 
	@OrderBy(value="apply_score")
	private SchoolVO2 school;
	private Integer apply_score;
	private Integer test_score;
	private String nation;
	private String gendar;
	private String major_string;
	@Transient
	private List<String> major;
	private boolean obey;
	@Transient
	private boolean isEnrolled;
	@Transient
	private String enrolled_major;
	@Transient
	private String apply_major_name;
	private String clazz;
	
	public String getClazz() {
		return clazz;
	}
	public void setClazz(String clazz) {
		this.clazz = clazz;
	}
	public String getApply_major_name() {
		StringBuilder sb = new StringBuilder();
		if (apply_major_name == null) {
			if (!StringUtil.isNull(major_string)) {
				String[] splits = major_string.split("%");
				for (String major_id : splits) {
					for (MajorVO2 vo : this.school.getMajors()) {
						if (vo.getMajor_id().equals(major_id)) {
							sb.append(vo.getMajor_name()).append(", ");
							break;
						}
					}
				}
			}
			apply_major_name = sb.toString();
		}
		
		return apply_major_name;
	}
	public void setApply_major_name(String apply_major_name) {
		this.apply_major_name = apply_major_name;
	}
	public String getEnrolled_major() {
		return enrolled_major;
	}
	public void setEnrolled_major(String enrolled_major) {
		this.enrolled_major = enrolled_major;
	}
	public String getMajor_string() {
		return major_string;
	}
	public void setMajor_string(String major_string) {
		this.major_string = major_string;
		if (!StringUtil.isNull(major_string)) {
			major = Arrays.asList(major_string.split("%"));
		}
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public SchoolVO2 getSchool() {
		return school;
	}
	public void setSchool(SchoolVO2 school) {
		this.school = school;
	}
	public Integer getApply_score() {
		return apply_score;
	}
	public void setApply_score(Integer apply_score) {
		this.apply_score = apply_score;
	}
	public Integer getTest_score() {
		return test_score;
	}
	public void setTest_score(Integer test_score) {
		this.test_score = test_score;
	}
	public String getNation() {
		return nation;
	}
	public void setNation(String nation) {
		this.nation = nation;
	}
	public String getGendar() {
		return gendar;
	}
	public void setGendar(String gendar) {
		this.gendar = gendar;
	}
	public List<String> getMajor() {
		if (major == null) {
			if (!StringUtil.isNull(major_string)) {
				major = Arrays.asList(major_string.split("%"));
			} else {
				return new ArrayList<String> ();
			}
		}
		return major;
	}
	public void setMajor(List<String> major) {
		this.major = major;
		StringBuilder sb = new StringBuilder();
		for (String _major : major) {
			sb.append(_major).append('%');
		}
		sb.deleteCharAt(sb.length() - 1);
		this.major_string = sb.toString();
	}
	public boolean isObey() {
		return obey;
	}
	public void setObey(boolean obey) {
		this.obey = obey;
	}
	public boolean isEnrolled() {
		return isEnrolled;
	}
	public void setEnrolled(boolean isEnrolled) {
		this.isEnrolled = isEnrolled;
	}
	
	
	
	
}
